package account

import (
	"context"

	"gitee.com/spume/common_service/app/billing/api/account/v1"
	"gitee.com/spume/common_service/app/billing/internal/model/do"
	"gitee.com/spume/common_service/app/billing/internal/service"
	"github.com/gogf/gf/v2/database/gdb"
	"github.com/gogf/gf/v2/frame/g"
)

func (c *ControllerV1) AccountCreateBatch(ctx context.Context, req *v1.AccountCreateBatchReq) (res *v1.AccountCreateBatchRes, err error) {
	err = g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) (err error) {
		ins := []*do.WalletAccount{}
		for _, val := range req.CurrencyTypes {
			ins = append(ins, &do.WalletAccount{
				MemberId:     req.MemberId,
				CurrencyType: val,
				Title:        req.Title,
				Balance:      0,
				Block:        0,
				TenantId:     req.TenantId,
			})
		}

		err = service.WalletAccount().CreateBatch(ctx, ins...)
		if err != nil {
			return
		}
		return
	})

	return
}
